package com.vhdadw.strategy;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class ShardingDBConfig {

    //启用存储数据库位置编号
    private static final List<String> dbPrefixList = new ArrayList<>();

    private static Random random = new Random();

    //配置启用哪些库的前缀
    static{
        dbPrefixList.add("0");
        dbPrefixList.add("1");
        dbPrefixList.add("a");
    }

   public static String getRandomDBPrefix(String code){

       int hashCode = code.hashCode();

       int index =  Math.abs(hashCode) % dbPrefixList.size();

       return dbPrefixList.get(index);
   }
}
